
package dialogs;

import main.DialogGridCreation;
import java.awt.BorderLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JTextField;
import main.GlobalMethods;
import main.Icons;

/**
 *
 * @author Raed Shomali
 */
public class ScaleFactorsDialog extends JDialog implements ActionListener
{
    JPanel scaleFactorPanel = new JPanel(); 
    
    private String[] driverNames = new String[]
    {
        "PREC" , "RESL" , "FLEX" , "TEAM" , "PMAT"
    };

    private String[] ratings = new String[]
    {
        "VLO" , "LO" , "NOM" , "HI" , "VHI" , "XHI"
    };

    private JTextField[][] scaleFactorFields = new JTextField[ driverNames.length ][ ratings.length ];

    JButton applyButton = new JButton( "Apply" ) ;
    JButton resetButton = new JButton( "Reset" ) ;
    JButton closeButton = new JButton( "Close" ) ;
    
    public ScaleFactorsDialog( JFrame frame )
    {
        super( frame );

        this.setModal( true );

        this.setTitle( "Scale Factors" );

        GlobalMethods.updateStatusBar( "Done." );

        // Buttons
        applyButton.addActionListener( this ) ;
        resetButton.addActionListener( this ) ;
        closeButton.addActionListener( this ) ;
        
        applyButton.setFocusable( false ) ;
        resetButton.setFocusable( false ) ;
        closeButton.setFocusable( false ) ;
        
        applyButton.setIcon( Icons.SAVE_ICON  ) ;
        resetButton.setIcon( Icons.RESET_ICON  ) ;
        closeButton.setIcon( Icons.CLOSE_ICON  ) ;
        
        for ( int i = 0 ; i < driverNames.length ; i++ )
        {
            for ( int j = 0 ; j < ratings.length ; j++ )
            {
                scaleFactorFields[ i ][ j ] = new JTextField() ;
                scaleFactorFields[ i ][ j ].setText( j + "" );
            }
        }
        
        // GUI
        DialogGridCreation.createTextFieldGrid( scaleFactorPanel  , driverNames , ratings , scaleFactorFields    );

        // Panel
        JPanel southPanel = new JPanel();
        southPanel.add( applyButton ) ;
        southPanel.add( resetButton ) ;
        southPanel.add( closeButton ) ;
        
        this.setLayout( new BorderLayout() );
        this.add( scaleFactorPanel ) ;
        this.add( southPanel , BorderLayout.SOUTH ) ;
        
        this.setDefaultCloseOperation( JDialog.DISPOSE_ON_CLOSE );
        this.setLocation( this.getOwner().getX() + 100 , this.getOwner().getY() + 100 );
        this.setResizable( false );
        this.setSize( 400 , 270 );
        this.setVisible( true );
    }

    public void actionPerformed( ActionEvent e )
    {
        if( e.getSource() == applyButton )
        {
        }
        else if( e.getSource() == resetButton )
        {
        }
        else
        {
            // Free Resources ... Close Window
            this.dispose() ;
        }
    }
}
